/*
 * Class ItemOption1
 *
 * Version 1.0
 *
 * Thursday, August 21, 2008
 *
 * Created by Palidino76
 */

package net.com.hydroPK.net.packethandler;

import net.com.hydroPK.Engine;
import net.com.hydroPK.model.Player;
import net.com.hydroPK.Server;
import net.com.hydroPK.model.misc.PlayerMethods;
import net.com.hydroPK.util.Misc;

public class ItemOption1 implements Packet {
    /**
     * Handles first item options, excluding things such as eating and drinking.
     *
     * @param p          The Player which the frame should be handled for.
     * @param packetId   The packet id this belongs to.
     * @param packetSize The amount of bytes being recieved for this packet.
     */
    public void handlePacket(Player p, int packetId, int packetSize) {
        if (p == null || p.stream == null) {
            return;
        }
        int itemSlot = p.stream.readUnsignedWordBigEndianA();
        int interfaceId = p.stream.readUnsignedWord();
        int junk = p.stream.readUnsignedWord();
        int itemId = p.stream.readUnsignedWord();
        if (itemSlot < 0 || itemId < 0) {
            return;
        }
        switch (interfaceId) {
            case 1847:
	if (Engine.playerItems.hasPlayerItemAmount(p, 2705, 1)) {
	p.teleportTo(3557, 9703, 3, 4, 0, 8939, 8941, 8, 0, -1, 0);
	//p.teleportTo(3557, 9702, 3);//barrows sarcaphugas
	p.message("you uncrumple the note,");
	p.message("and a strange power comes over you");
	p.message("");
	}
		break;
            case 2705:
	{
	    p.getActionSender().showInterface(p, 275);
                    p.getActionSender().setString(p, "Clue", 275, 2);
	    p.getActionSender().setString(p, "You have found this Clue Scroll from a Monster Drop", 275, 11);
	    p.getActionSender().setString(p, "To Complete this Clue Scroll, you must go through 3 parts.", 275, 12);
	    p.getActionSender().setString(p, "Your First Task is to do ::wt", 275, 13);
	    p.getActionSender().setString(p, "once there, you will find an unknown area.", 275, 14);
	    p.getActionSender().setString(p, "search the area, and you will find something.", 275, 15);
	    p.getActionSender().setString(p, "next, you use the item you find, and it takes you to another", 275, 16);
	    p.getActionSender().setString(p, "unknown area. Search this place, and you will find a ring.", 275, 17);
	    p.getActionSender().setString(p, "wear the ring, and then Operate it.", 275, 18);
	    p.getActionSender().setString(p, "You are somewhere never before seen.", 275, 19);
	    p.getActionSender().setString(p, "Go West, until you find a door that you can enter..", 275, 20);
	    p.getActionSender().setString(p, "once you find your door, search the house!", 275, 21);
	    p.getActionSender().setString(p, "your prize will be on the first floor!", 275, 22);
	    p.getActionSender().setString(p, "", 275, 23);
	    p.getActionSender().setString(p, "", 275, 24);
	    p.getActionSender().setString(p, "", 275, 25);
	    p.getActionSender().setString(p, "", 275, 26);
	    p.getActionSender().setString(p, "", 275, 27);
	    p.getActionSender().setString(p, "", 275, 28);
	    p.getActionSender().setString(p, "", 275, 29);
	    p.getActionSender().setString(p, "", 275, 30);
	}
		break;
            case 12175:/*Spirit Wolf*/
                if (p.FamiliarID > 0) {
                    p.getActionSender().sendMessage(p, "You cannot summon more than one familiar at a time.");
                } else {
                    Engine.playerItems.deleteItem(p, 12047, itemSlot, 1);
                    p.getActionSender().sendMessage(p, "You summon  spirit wolf.");
                    p.getActionSender().setTab(p, 80, 662);
                    p.getActionSender().animateInterfaceId(p, 9805, 662, 3);
                    p.getActionSender().setNPCId(p, 6829, 662, 3);
                    Engine.newNPC(6829, p.absX, p.absY + 1, p.heightLevel, p.absX + 1, p.absY + 1, p.absX + -1, p.absY + -1, false, p.playerId);
                    //p.addSkillXP(15, 23);
		break;
                }
		
                
            case 387: // Unequip item.
                if (itemSlot < p.equipment.length && p.equipment[itemSlot] == itemId) {
                    if (!Engine.playerItems.addItem(p, p.equipment[itemSlot], p.equipmentN[itemSlot])) {
                        break;
                    }
                    if (itemId == 4031) {
                        p.convertPlayerToNpc(-1);
                        p.updatePlayerAppearance(p.playerWeapon.getWalkEmote(p.equipment[3]), p.playerWeapon.getStandEmote(p.equipment[3]),
                                p.playerWeapon.getRunEmote(p.equipment[3]));
                        p.updatePlayer(true);
                    }

                    if (itemId == 3053) {
                        p.getActionSender().sendMessage(p, "You cannot un-equip your battlestaff while during the" +
                                " mage arena minigame.");
                        return;
                    }
                    if (itemSlot == 3 && (p.usingAutoCast || p.castAuto)) {
                        p.castAuto = false;
                        p.usingAutoCast = false;
                        p.autoCastDelay = 0;
                        if (itemId == 4675) {
                            p.resetAttack();
                        }
                    }
                    p.equipment[itemSlot] = -1;
                    p.equipmentN[itemSlot] = 0;
                    PlayerMethods pm = new PlayerMethods(p);
                    pm.setAttackPlayer(false);
                    p.getActionSender().setItems(p, 387, 28, 94, p.equipment, p.equipmentN);
                    p.playerWeapon.setWeapon();
                    p.appearanceUpdateReq = true;
                    p.updateReq = true;
                    p.calculateEquipmentBonus();
                }
                break;
            default:
                Misc.println("[" + p.username + "] Item option 1: " + interfaceId);
                break;
        }
    }
}
